package com.scm.biz.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.scm.biz.dto.EncasementDto;
import com.scm.biz.service.EncasementItemService;
import com.scm.biz.service.EncasementService;
import com.scm.core.bean.exp.UfdmException;
import com.scm.core.bean.resp.RespBean;
import com.scm.utils.UploadAndDownUtil;

@Controller
@RequestMapping("/encasement")
public class EncasementAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3589135877403859070L;
	@Resource
	EncasementService encasementService;
	@Resource
	EncasementItemService encasementItemService;
	@RequestMapping("/insertEncasement")
	@ResponseBody
	public RespBean<String> insertEncasement(EncasementDto encasementDto,Integer opFlag){	
	
		encasementService.insert(encasementDto,opFlag);
		RespBean<String> respBean = new RespBean<String>();
		return respBean;
	}
	@RequestMapping("/add")
	public ModelAndView addEncasement(Long productionPatternId){
		ModelAndView mvAndView = new ModelAndView("order/production_encasement_add");
		mvAndView.addObject("historyList",encasementService.selectListByProductionPatternId(productionPatternId));
		mvAndView.addObject("productionPatternId",productionPatternId);
		return mvAndView;
	}
	@RequestMapping("/addArrivedate")
	public ModelAndView addArrivedate(Long productionPatternId){
		ModelAndView mvAndView = new ModelAndView("order/production_encasement_add_arrivedate");
		mvAndView.addObject("encasementList",encasementService.selectListByProductionPatternId(productionPatternId));
	
		mvAndView.addObject("productionPatternId",productionPatternId);
		return mvAndView;
	}
	@RequestMapping("/saveArriveDate")
	@ResponseBody
	public RespBean<String> saveArriveDate(Long productionPatternId,Long encasementId,String arriveDate){	
		encasementService.saveArriveDate(productionPatternId, encasementId, arriveDate);
	
		RespBean<String> respBean = new RespBean<String>();
		return respBean;
	}
	@RequestMapping("/saveArriveDateFinish")
	@ResponseBody
	public RespBean<String> saveArriveDateFinish(Long productionPatternId,Long encasementId,String arriveDate){	
		encasementService.saveArriveDateFinish(productionPatternId);
	
		RespBean<String> respBean = new RespBean<String>();
		return respBean;
	}
	/**
	 * 大货款式装箱单详情（下载）
	 * @param productionPatternId
	 * @return
	 */
	@RequestMapping("/detail")
	public ModelAndView detail(Long productionPatternId){
		ModelAndView mv=new ModelAndView("order/production_encasement_detail");
		mv.addObject("historyList", encasementService.selectListByProductionPatternId(productionPatternId));
		mv.addObject("productionPatternId",productionPatternId);
		return mv;
	}
	
	/**
	 * 产生PDF文件
	 * @param request
	 * @param response
	 * @return
	 * @throws UfdmException 
	 * @throws Exception 
	 */
	@RequestMapping("/exportPdf")
	@ResponseBody
	public RespBean<String> expoprtPdf(MultipartHttpServletRequest request, HttpServletResponse response) throws UfdmException{
		UploadAndDownUtil.expoprtPdf("/pdf/zxd_", request, response);
		RespBean<String> respBean=new RespBean<String>();
		return respBean;
	}
	
	/**
	 * 下载装箱单
	 * @param id
	 * @param req
	 * @param res
	 * @throws UfdmException
	 */
	@RequestMapping("/downPdf")
	public void DownPdf(Long productionPatternId,HttpServletRequest req, HttpServletResponse res) throws UfdmException{
		UploadAndDownUtil.downFile("装箱单.pdf", "/pdf/zxd_"+productionPatternId+".pdf", req, res);
	}
}
